package com.Cychat.chat.mapper;

import com.Cychat.chat.entity.VO.FriendVO;
import com.Cychat.commons.entity.pojo.Friend;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Auther: 刘博文
 * Date: 2025/10/29:20:00
 * Description: 朋友关系映射接口
 */
@Mapper
public interface FriendMapper extends BaseMapper<Friend> {

    /**
     * 查询用户的所有好友（包含好友的用户信息）
     *
     * @param userId 用户ID
     * @return 好友列表
     */
    @Select("SELECT f.*, u.user_id , u.nick_name , u.avatar_url, \n" +
            "u.gender , u.country , u.province , u.city \n" +
            "FROM friend f\n" +
            "LEFT JOIN user u ON f.friend_user_id = u.user_id \n" +
            "WHERE f.user_id = #{userId}\n" +
            " AND f.friend_status = 1")
    List<FriendVO> selectAllFriendsWithUser(@Param("userId") Long userId);

    /**
     * 查询用户收到的好友申请（包含申请者的用户信息）
     *
     * @param userId 用户ID
     * @return 好友申请列表
     */
    @Select("SELECT f.*, u.user_id , u.nick_name , u.avatar_url , \n" +
            " u.gender , u.country , u.province , u.city \n" +
            " FROM friend f \n" +
            " LEFT JOIN USER u ON f.user_id = u.user_id \n" +
            " WHERE f.friend_user_id = #{userId} AND f.friend_status = 0")
    List<FriendVO> selectFriendApplyWithUser(@Param("userId") Long userId);

    /**
     * 查询用户收到的所有好友申请记录（包括待处理、已同意、已拒绝）
     *
     * @param userId 用户ID
     * @return 好友申请记录列表
     */
    @Select("SELECT f.*, u.user_id , u.nick_name , u.avatar_url , \n" +
            " u.gender , u.country , u.province , u.city \n" +
            " FROM friend f \n" +
            " LEFT JOIN user u ON f.user_id = u.user_id \n" +
            " WHERE f.friend_user_id = #{userId} AND f.friend_status IN (0, 1, 2, 4)")
    List<FriendVO> selectAllFriendRequestsWithUser(@Param("userId") Long userId);
}